home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / DATABASE / OBJ1_2.ZIP;1 / C_WINDOW.PRG < prev    next >
Encoding:
Text File  |  1993-01-27  |  12.7 KB  |  387 lines

  1. //*****************************************************************************
  2. // C_Window.prg
  3. // Window class for OBJECT v2.03
  4. // Copyright (c) 1991, JHK, JHK-Software, Piestany
  5. // Compile with: /N/M/W/A
  6. //-----------------------------------------------------------------------------
  7.  
  8. #include "Object.ch"
  9.  
  10. static WList:={}       //this stack contain all visible windows
  11. static MinStack:={}    //stack for minimized windows
  12.  
  13. create class Window from Box    //Usage sequence: Init,Paint, (Drag,Max,Min,..) Done
  14.   export:
  15.   var ID       //0                   //window ID (1..x)
  16.   var WRow     //3                   //saved window coord. for Restore()
  17.   var WCol     //4                   //...
  18.   var WRowSize //MaxRow()-7          //...
  19.   var WColSize //MaxCol()-9          //...
  20.   var IsMax    //false               //current state of window (is maximize?)
  21.   var IsMin    //false               //...
  22.   var MaxRows  //MaxRow()-3          //maximum available RowSize
  23.   var MaxCols  //MaxCol()-1          //maximum available ColSize
  24.   var MinRows  //1                   //minimum available RowSize
  25.   var MinCols  //5                   //minimum available ColSize
  26.   var UpFlag   //false               //if is true then not show Window:ID
  27.   var Screen   //""                  //saved screen before painting UpWindow
  28.   var UpScreen //""                  //Up color atributes,speed optimization
  29.   var BkScreen //""                  //BackGround color atributes, speed optimization
  30.   var RCInfo   //""                  //... used as flag for changed window coord.
  31.   var InfoMsg  //""                  //show this message into bottom of window (if !empty())
  32.   var Frame    //(object of Frame)   //need for Drag()
  33.   method New=WindowNew            //o:New()
  34.   method Init=WindowInit          //o:Init(Name,R,C,Rs,Cs,Clr,Shadow)
  35.   method GoodInit=WindowGoodInit  //o:GoodInit(Name,R,C,Rs,Cs,CurSize,Clr,Shadow)
  36.   method VPaint=WindowVPaint      //o:VPaint()             //virtual paint, use (overwrite) in child classes for redrawing window.
  37.   method SaveIn=WindowSaveIn      //o:SaveIn()             //save screen inside window, speed optimization
  38.   method DoInfo=WindowDoInfo      //o:DoInfo()             //write any info into bottom of window (if exist)
  39.   method Paint=WindowPaint        //o:Paint(IsTop)         //if not on top of stack then color is Desk (not selected)
  40.   method Top=WindowTop            //o:Top(lRePaint)        //move window on top of stack, and paint it.
  41.   method RePaint=WindowRePaint    //o:RePaint(lClearDesk)  //redraw all visible window
  42.   method Drag=WindowDrag          //o:Drag(lCanSize)       //move size current window
  43.   method Maximize=WindowMaximize  //o:Maximize()           //maximize window
  44.   method Minimize=WindowMinimize  //o:Minimize(lShow)      //minimize, if lShow is false then no RePaint() is invoked.
  45.   method Restore=WindowRestore    //o:Restore()            //restore window.
  46.   method Done=WindowDone          //o:Done(lRePaint)       //work around MinStack
  47.   endclass
  48.  
  49. //-----------------------------------------------------------------------------
  50. // GetWList() --> WList
  51. // return window list
  52. //
  53. function GetWList()
  54.   return(WList)
  55.  
  56.  
  57. //-----------------------------------------------------------------------------
  58. // RePaintDesktop() --> nil
  59. // redraw entire screen
  60. //
  61. procedure RePaintDesktop()
  62.   SaveDOut(ResTxt(172))
  63.     DispBegin()
  64.     @ 1,0,MaxRow()-1,MaxCol() box "∞∞∞∞∞∞∞∞∞" color m->Color:Desk   //create background
  65.     if !Empty(WList); WList[1]:Paint(); endif
  66.     DispEnd()
  67.     AEval(WList,{|w|w:Paint()},2)
  68.   RestDOut()
  69.   return
  70.  
  71.  
  72. //*****************************************************************************
  73. // Window:New() --> self
  74. // default values for this object
  75. //
  76. constructor WindowNew()
  77.   ::ID:=0
  78.   ::WRow:=3
  79.   ::WCol:=4
  80.   ::WRowSize:=MaxRow()-7
  81.   ::WColSize:=MaxCol()-9
  82.   ::IsMax:=false
  83.   ::IsMin:=false
  84.   ::MaxRows:=MaxRow()-3
  85.   ::MaxCols:=MaxCol()-1
  86.   ::MinRows:=1
  87.   ::MinCols:=5
  88.   ::UpFlag:=false
  89.   ::Screen:=""
  90.   ::UpScreen:=""
  91.   ::BkScreen:=""
  92.   ::RCInfo:=""
  93.   ::InfoMsg:=""
  94.   ::Frame:=(object of Frame)
  95.   return(self)
  96.  
  97.  
  98. //*****************************************************************************
  99. // Window:Init(Name,R,C,Rs,Cs,Clr,Shadow) --> true
  100. // initialize new window.
  101. //
  102. method function WindowInit(Name,R,C,Rs,Cs,Clr,Shadow)
  103.   ::super(Box):Init(Name,R,C,Rs,Cs,Clr,Shadow)
  104.   return(EndInit(self))
  105.  
  106.  
  107. //*****************************************************************************
  108. // Window:GoodInit(Name,R,C,Rs,Cs,CurSize,Clr,Shadow) --> true
  109. // initialize new window.
  110. //
  111. method function WindowGoodInit(Name,R,C,Rs,Cs,CurSize,Clr,Shadow)
  112.   ::super(Box):GoodInit(Name,R,C,Rs,Cs,CurSize,Clr,Shadow)
  113.   return(EndInit(self))
  114.  
  115.  
  116. //-----------------------------------------------------------------------------
  117. // Window::EndInit() --> true
  118. // initialize Window extension instvars.
  119. //
  120. static function EndInit(Window)
  121.   local i:=1
  122.   Window:RowSize:=Min(Window:RowSize,Window:MaxRows)
  123.   Window:ColSize:=Min(Window:ColSize,Window:MaxCols)
  124.   Window:WRow:=Window:Row
  125.   Window:WCol:=Window:Col
  126.   Window:WRowSize:=Window:RowSize
  127.   Window:WColSize:=Window:ColSize
  128.   while AScan(WList,{|e|e:ID==i})>0; i++; endwhile
  129.   Window:ID:=i
  130.   AAdd(WList,Window)
  131.   return(true)
  132.  
  133.  
  134. //*****************************************************************************
  135. // Window:VPaint() --> true
  136. // virtual method for writting users data into inside of window.
  137. //
  138. method function WindowVPaint()    //I reccomend You will overwrite it
  139.   return(true)                    //this method in derived classes.
  140.  
  141.  
  142. //*****************************************************************************
  143. // Window:SaveIn() --> true
  144. // save screen inside window for speed
  145. //
  146. method function WindowSaveIn()
  147.   if !::IsMin
  148.     ::RCInfo:=NTrim(::RowSize)+NTrim(::ColSize)
  149.     ::UpScreen:=SaveScreen(::Row+1,::Col+1,::Row+::RowSize,::Col+::ColSize)
  150.     ::BkScreen:=Transform(::UpScreen,Replicate("X"+Chr(Color2Num(m->Color:Desk)),Len(::UpScreen)/2))
  151.   endif
  152.   return(true)
  153.  
  154.  
  155. //*****************************************************************************
  156. // Window:DoInfo(IsTop) --> true
  157. // write any info into bottom of window (if exist)
  158. //
  159. method function WindowDoInfo(IsTop)
  160.   local R,C,s
  161.   if !Empty(::InfoMsg)
  162.     default IsTop to (::ID==ATail(WList):ID)
  163.     R:=Row()
  164.     C:=Col()
  165.     s:=Left(::InfoMsg,::ColSize-2)
  166.     s+=Replicate(if(IsTop,"Õ","ƒ"),::ColSize-2-Len(s))
  167.     @ ::Row+::RowSize+1,::Col+2 say s color ::Color
  168.     SetPos(R,C)
  169.   endif
  170.   return(true)
  171.  
  172.  
  173. //*****************************************************************************
  174. // Window:Paint(IsTop) --> true
  175. // physically write window into screen.
  176. //
  177. method function WindowPaint(IsTop)
  178.   local Clr:=::Color
  179.   default IsTop to (::ID==ATail(WList):ID)
  180.   if ::UpFlag and Empty(::Screen); ::Screen:=SaveScr(); endif
  181.   if ::IsMin
  182.     @ ::Row,::Col say "("+NTrim(::ID)+")[ "+::Name+" ]" color ListAsArray(m->Color:Edit)[if(IsTop,nEnhanced,nNormal)]
  183.   else
  184.     DispBegin()
  185.     ::super(Box):Paint(IsTop)
  186.     if !Empty(::InfoMsg)
  187.       @ ::Row+::RowSize+1,::Col+2 say Left(::InfoMsg,::ColSize-2) color ::Color
  188.     endif
  189.     if !::UpFlag
  190.       @ ::Row,::Col+1 say "("+NTrim(::ID)+if(::ID<=9,")","") color ::Color
  191.       @ ::Row,::Col+::ColSize-if(::IsMax,2,3) say if(::IsMax,"()","()") color ::Color
  192.     endif
  193.     if !(::RCInfo==(NTrim(::RowSize)+NTrim(::ColSize)))
  194.       if !IsTop; ::Color:=m->Color:Desk; endif  //grayed unselect window
  195.       ::VPaint()
  196.       ::Color:=Clr
  197.       if IsTop; ::SaveIn(); endif
  198.     else
  199.       if IsTop
  200.         RestScreen(::Row+1,::Col+1,::Row+::RowSize,::Col+::ColSize,::UpScreen)
  201.       else
  202.         RestScreen(::Row+1,::Col+1,::Row+::RowSize,::Col+::ColSize,::BkScreen)
  203.       endif
  204.     endif
  205.     DispEnd()
  206.   endif
  207.   if ::IsMin
  208.     SetPos(::Row-1,::Col+2)
  209.   else
  210.     SetPos(::Row+1,::Col+1)
  211.   endif
  212.   ShowTime()
  213.   return(true)
  214.  
  215.  
  216. //*****************************************************************************
  217. // Window:Top(lRePaint) --> true
  218. // moving window on top of window stack and paint it.
  219. //
  220. method function WindowTop(lRePaint)
  221.   local i:=AScan(WList,{|e|e:ID==::ID})    //find the window in WindowList
  222.   default lRePaint to true
  223.   if ::UpFlag and Empty(::Screen)
  224.     ::Screen:=SaveScr()
  225.   endif
  226.   ADel(WList,i)             //delete from WList
  227.   WList[Len(WList)]:=self   //push on top WList
  228.   if lRePaint
  229.     ::RePaint(true)         //repaint all windows
  230.   else
  231.     if Len(WList)>=2
  232.       WList[Len(WList)-1]:Paint(false)  //paint (unselected colors) last active window
  233.     endif
  234.     ::Paint(true)                  //top = paint new selected windows
  235.   endif
  236.   return(true)
  237.  
  238.  
  239. //*****************************************************************************
  240. // Window:RePaint(lClearDesk) --> true
  241. // repaint all windows.
  242. //
  243. method function WindowRePaint(lClearDesk)
  244.   default lClearDesk to true
  245.   SaveDOut(ResTxt(172))
  246.     DispBegin()
  247.       if ::UpFlag and Empty(::Screen)
  248.         ::Screen:=SaveScr()
  249.       endif
  250.       if lClearDesk
  251.         @ 1,0,MaxRow()-1,MaxCol() box "∞∞∞∞∞∞∞∞∞" color m->Color:Desk   //create background
  252.       endif
  253.       if !Empty(WList); WList[1]:Paint(); endif
  254.     DispEnd()
  255.     AEval(WList,{|w|w:Paint()},2)
  256.   RestDOut()
  257.   return(true)
  258.  
  259.  
  260. //*****************************************************************************
  261. // Window:Drag(lCanSize) --> true
  262. // moving window in screen area.
  263. //
  264. method function WindowDrag(lCanSize)
  265.   default lCanSize to !::IsMin
  266.   if ::IsMin
  267.     ::Frame:Init(::Row,::Col,-1,Len(NTrim(::ID))+Len(::Name)+4)
  268.   else
  269.     ::Frame:Init(::Row,::Col,::RowSize,::ColSize)
  270.   endif
  271.   ::Frame:MaxRows:=::MaxRows
  272.   ::Frame:MaxCols:=::MaxCols
  273.   ::Frame:MinRows:=::MinRows
  274.   ::Frame:MinCols:=::MinCols
  275.   if ::Frame:Drag(lCanSize)
  276.     ::Row:=::Frame:Row             //save
  277.     ::Col:=::Frame:Col
  278.     if ! ::IsMin
  279.       ::RowSize:=::Frame:RowSize
  280.       ::ColSize:=::Frame:ColSize
  281.       SaveCoords(self)           //i am not sure that this line must exist...
  282.     endif
  283.     ::RePaint()                    //repaint
  284.   endif
  285.   return(true)
  286.  
  287.  
  288. //*****************************************************************************
  289. // Window:Maximize() --> true
  290. // maximize window in screen area.
  291. //
  292. method function WindowMaximize()
  293.   NoMinimize(self)
  294.   SaveCoords(self)
  295.   ::IsMax:=true
  296.   ::RowSize:=::MaxRows
  297.   ::ColSize:=::MaxCols
  298.   ::Row:=Int((MaxRow()-3-::MaxRows)/2)+1
  299.   ::Col:=Int((MaxCol()-1-::MaxCols)/2)
  300.   if ::MaxRows==MaxRow()-3 and ::MaxCols==MaxCol()-1
  301.     ::Paint(true)
  302.   else
  303.     ::RePaint()
  304.   endif
  305.   return(true)
  306.  
  307.  
  308. //*****************************************************************************
  309. // Window:Minimize(lRePaint) --> true
  310. // minimize window in screen area, if lShow==false then no write into screen!
  311. //
  312. method function WindowMinimize(lRePaint)
  313.   local R:=MaxRow()-1
  314.   local C:=1
  315.   default lRePaint to true
  316.   if ! ::IsMin
  317.     while AScan(MinStack,{|w| (w:Row==R)and(w:Col==C) })>0
  318.       C+=Int(MaxCol()/2)
  319.       if C>=MaxCol(); R--; C:=1; endif
  320.     endwhile
  321.     SaveCoords(self)
  322.     ::Row:=R
  323.     ::Col:=C
  324.     AAdd(MinStack,self)
  325.     ::IsMin:=true
  326.     if lRePaint; ::RePaint(); endif
  327.   endif
  328.   return(true)
  329.  
  330.  
  331. //*****************************************************************************
  332. // Window:Restore() --> true
  333. // restore origin window size and repaint it.
  334. //
  335. method function WindowRestore()
  336.   NoMinimize(self)
  337.   ::RowSize:=::WRowSize
  338.   ::ColSize:=::WColSize
  339.   ::IsMax:=false
  340.   ::RePaint()
  341.   return(true)
  342.  
  343.  
  344. //*****************************************************************************
  345. // Window:Done(lRePaint) --> true
  346. // destroy the window.
  347. //
  348. method function WindowDone(lRePaint)
  349.   default lRePaint to false
  350.   NoMinimize(self)
  351.   ATrueDel(WList,AScan(WList,{|e|e:ID==::ID}))
  352.   if ::UpFlag and !Empty(::Screen)
  353.     RestScr(::Screen)
  354.   else
  355.     if lRePaint; ::RePaint(); endif
  356.   endif
  357.   return(true)
  358.  
  359.  
  360. //-----------------------------------------------------------------------------
  361. // Window::NoMinimize() --> true
  362. // work around un_minimize window.
  363. //
  364. static function NoMinimize(Window)
  365.   Window:Row:=Window:WRow
  366.   Window:Col:=Window:WCol
  367.   if Window:IsMin
  368.     ATrueDel(MinStack,AScan(MinStack,{|e|e:ID==Window:ID}))
  369.     Window:IsMin:=false
  370.   endif
  371.   return(true)
  372.  
  373.  
  374. //-----------------------------------------------------------------------------
  375. // Window::SaveCoords() --> true
  376. // save current window coords.
  377. //
  378. static function SaveCoords(Window)
  379.   Window:WRow:=Window:Row                    //save for Maximize/Minimize
  380.   Window:WCol:=Window:Col
  381.   Window:WRowSize:=Window:RowSize
  382.   Window:WColSize:=Window:ColSize
  383.   return(true)
  384.  
  385. //------------------------------------------------------- eof (c)JHK ----------
  386.  
  387.